// base_setup.h
// Customizer_Base
// Protea Customizer/Customizer Pro / Setup for Customizer/Customizer Pro shared functionality
// Copyright (C) 2003, 2004, 2005 eXegeSys, Inc.
// Copyright (C) 2008 Bruce A. James
//
// This program is part of the Protea Project.
//
// The Protea Project is free software; you can redistribute it and/or modify it 
// under the terms of the GNU General Public License as published by the 
// Free Software Foundation, either version 3 of the License, or (at your 
// option) any later version.
//
// The Protea Project is distributed in the hope that it will be useful, but 
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
// for more details.
// 
// You should have received a copy of the GNU General Public License along 
// with this program.  If not, see <http://www.gnu.org/licenses/>.
//
// Please send correspondence to:
//
// theproteaproject@gmail.com
//

#ifndef __PROTEA_BASE_SETUP__ 
#define __PROTEA_BASE_SETUP__

//@ MAN Protea Advanced Customizer

//@ COP 2003, 2004, 2005 eXegeSys, Inc.
//@ COP 2008 Bruce A. James

//@ SCT 1 Database Definitions
//@ SCT 2 Transaction Descriptions
//@ SCT 3 Subtransaction Descriptions

#include "../../defns1.h"
#include "../../../SDK/ToolsInterface.h"
using namespace ProteaApp1;

#define DESIGN_MODE

enum verify_type {
	VERIFY_ADD = 0,
	VERIFY_CHANGE = 1,
	VERIFY_DELETE = 2,
	VERIFY_REVIEW = 3,
	VERIFY_COPY = 4
};

#define TRANSACTION(x) XCTransactionInfo* x( XCTransactionInfo* transaction )
#define TRANSACTION_CODE(x) XCTransactionInfo* x( XCTransactionInfo* transaction )
#define LOG_TRANSACTION() LogTransaction( transaction, &txnvars )


///////////////////////////////////////////////////
//
// Utilities
//
///////////////////////////////////////////////////
__EXPORT void LogTransaction( XCTransactionInfo* transaction, XCTransactionVars* vars );

__EXPORT void ValidateAppNumber( XCTransactionVars* vars );
__EXPORT void ValidateName( const int field_nbr, const XCBuffer* buffer, const long message, XCTransactionVars* vars );

__EXPORT bool LookupNumberFromName( XCTransactionVars* vars, XCBuffer* source, XCBuffer* dest, long number_field, long name_field, long buffer, long db_number_field=0, long db_name_field=0 );
__EXPORT bool LookupNameFromNumber( XCTransactionVars* vars, XCBuffer* source, XCBuffer* dest, long number_field, long name_field, long buffer, long db_number_field=0, long db_name_field=0 );

__EXPORT void DSGetFieldFormatNames( XCTransactionVars* vars, XCBuffer* buffer, bool get_field, XCBuffer* format_buffer = NULL, XCBuffer* field_buffer = NULL );
__EXPORT XCDBStatement* GetLitGroup( XCBuffer* TransBuf, XCTransactionVars* vars );

__EXPORT void FixFieldType( XCBuffer* format, XCBuffer* field, XCBuffer* ds, XCTransactionVars* vars, bool ds_change = false );

__EXPORT bool IsValidDataType( XCBuffer* buf, XCTransactionVars* vars );
__EXPORT bool IsDatabaseBuffer( XCBuffer* buf );
__EXPORT bool SystemObject( XCField* field );

__EXPORT long SelectCountMany( long table, XCTransactionVars* vars, XCField** FieldList );
__EXPORT long SelectCountMany( long table, XCTransactionVars* vars, long numkeys, ... );

///////////////////////////////////////////////////
//
// Subtransactions
//
///////////////////////////////////////////////////

// base_setup.cpp
__EXPORT void Database_Review( XCBuffer* Buf, XCTransactionVars* Vars, long Field );

// application.cpp
__EXPORT bool ApplDefnRetrieve( XCBuffer* appl_defn, XCTransactionVars* vars );
__EXPORT void ApplDefnDelete( XCBuffer* appl_defn, XCTransactionVars* vars );
__EXPORT void ApplDefnVerify( XCBuffer* appl_defn, verify_type verify_mode, XCTransactionVars* vars );

// components.cpp
__EXPORT void ComponentVerify( XCBuffer* buf, verify_type verify_mode, XCTransactionVars* vars, XCBuffer* orig );
__EXPORT void ComponentChange( XCBuffer* input, XCBuffer* compare, XCTransactionVars* vars );
__EXPORT bool ComponentRetrieve( XCBuffer* buf, XCTransactionVars* vars );

// database.cpp
__EXPORT void DatabaseDefnDeleteAll( XCBuffer* buf, XCTransactionVars* vars );
__EXPORT bool DatabaseDefnRetrieve( XCBuffer* database_defn, XCTransactionVars* vars );
__EXPORT XCDBStatement* DatabaseReviewTables( XCBuffer* dataset_descr, XCTransactionVars* vars );
__EXPORT void DatabaseDefnVerify( XCBuffer* database_defn, verify_type verify_mode, XCTransactionVars* vars );
__EXPORT void DatabaseDefnAdd( XCBuffer* database_defn, XCTransactionVars* vars );
__EXPORT void DatabaseDefnDelete( XCBuffer* database_defn, XCTransactionVars* vars );

// data_structures.cpp
__EXPORT void DataStructureAdd( XCBuffer* input, XCBuffer* format, XCBuffer* field, XCTransactionVars* vars );
__EXPORT void DataStructureChange( XCBuffer* input, XCBuffer* compare, XCTransactionVars* vars );
__EXPORT bool DataStructureRetrieve( XCBuffer* ds, XCTransactionVars* vars );
__EXPORT XCDBStatement* DataStructureReviewField( XCBuffer* ds, XCTransactionVars* vars );
__EXPORT XCDBStatement* DataStructureReviewFormat( XCBuffer* ds, XCTransactionVars* vars );
__EXPORT void DataStructureVerify( XCBuffer* input, verify_type verify_mode, XCBuffer* format, XCBuffer* field, XCTransactionVars* vars, bool pro_mode, XCBuffer* original=NULL );
__EXPORT XCDBStatement* GetFieldWhereUsed( XCBuffer* ds, XCTransactionVars* vars );
__EXPORT XCDBStatement* GetLitGroupWhereUsed( XCBuffer* ds, XCTransactionVars* vars );

__EXPORT void AddDataStructureInternal( XCTransactionVars* vars, bool pro_mode );
__EXPORT void ChgDataStructureInternal( XCTransactionVars* vars, bool pro_mode );
__EXPORT void DelDataStructureInternal( XCTransactionVars* vars, bool pro_mode );

// db_primary.cpp
__EXPORT void DatabaseAddPrimary( XCBuffer* buffer, XCTransactionVars* vars );
__EXPORT void DatabaseChgPrimary( XCBuffer* buffer, XCBuffer* original, XCTransactionVars* vars );
__EXPORT void DatabaseDelPrimary( XCBuffer* buffer, XCTransactionVars* vars );
__EXPORT bool DatabaseRetrievePrimary( XCBuffer* buffer, XCTransactionVars* vars );

// fields.cpp
__EXPORT bool FieldDescRetrieve( XCBuffer* fielddesc, XCTransactionVars* vars );
__EXPORT void FieldDescVerify( XCBuffer* input, verify_type verify_mode, XCTransactionVars* vars, bool pro_mode, XCBuffer* orig = NULL );
__EXPORT void FieldDescAdd( XCBuffer* input, XCTransactionVars* vars, bool use_system_pool );
__EXPORT void FieldDescDelete( XCBuffer* input, XCTransactionVars* vars );
__EXPORT void FieldDescChange( XCBuffer* input, XCBuffer* orig, XCTransactionVars* vars );
__EXPORT void FieldDescDeleteAll( XCBuffer* input, XCTransactionVars* vars );

__EXPORT void AddFieldInternal( XCTransactionVars* vars, bool pro_mode = false );
__EXPORT void ChgFieldInternal( XCTransactionVars* vars, bool pro_mode = false );
__EXPORT void DelFieldInternal( XCTransactionVars* vars, bool pro_mode = false );
__EXPORT void CopyFieldInternal( XCTransactionVars* vars, bool pro_mode = false );

// field_relate.cpp
__EXPORT void FieldRelateVerify( XCBuffer* input, verify_type verify_mode, XCTransactionVars* vars );
__EXPORT bool FieldRelateRetrieve( XCBuffer* field_relate, XCTransactionVars* vars );
__EXPORT void FieldRelateAdd( XCBuffer* field_relate, XCTransactionVars* vars );
__EXPORT void FieldRelateDelete( XCBuffer* field_relate, XCTransactionVars* vars );
__EXPORT void FieldRelateDeleteField( XCBuffer* input, XCTransactionVars* vars );
__EXPORT XCDBStatement* FieldRelateFind( XCBuffer* input, XCTransactionVars* vars );

// formats.cpp
__EXPORT bool FormatDescRetrieve( XCBuffer* formatdesc, XCTransactionVars* vars );
__EXPORT void FormatDescAdd( XCBuffer* formatdesc, XCTransactionVars* vars, bool use_system_pool );
__EXPORT void FormatDescChange( XCBuffer* input, XCBuffer* orig, XCTransactionVars* vars );
__EXPORT void FormatDescVerify( XCBuffer* input, verify_type verify_mode, XCTransactionVars* vars, bool pro_mode, XCBuffer* orig = NULL );
__EXPORT void FormatDescDelete( XCBuffer* input, XCTransactionVars* vars );
__EXPORT void FormatDescDeleteAll( XCBuffer* input, XCTransactionVars* vars );

__EXPORT void AddFormatInternal( XCTransactionVars* vars, bool pro_mode = false );
__EXPORT void ChgFormatInternal( XCTransactionVars* vars, bool pro_mode = false );
__EXPORT void DelFormatInternal( XCTransactionVars* vars, bool pro_mode = false );
__EXPORT void CopyFormatInternal( XCTransactionVars* vars, bool pro_mode = false );

// languages.cpp
__EXPORT void LanguageDefnVerify( XCBuffer* buf, XCTransactionVars* vars, verify_type verify_mode );

// literals.cpp
__EXPORT void LiteralDefnVerify( XCBuffer* buf, XCTransactionVars* vars, verify_type verify_mode, bool pro_mode, XCBuffer* orig = NULL ); 
__EXPORT bool LiteralDefnRetrieve( XCBuffer* buf, XCTransactionVars* vars );
__EXPORT void LiteralDefnAdd( XCBuffer* buf, XCTransactionVars* vars, bool pro_mode );
__EXPORT void LiteralDefnChange( XCBuffer* input, XCBuffer* orig, XCTransactionVars* vars );
__EXPORT void LiteralDefnDelete( XCBuffer* buf, XCTransactionVars* vars );
__EXPORT void LiteralDefnDeleteAll( XCBuffer* input, XCTransactionVars* vars );

__EXPORT void AddLiteralInternal( XCTransactionVars* vars, bool pro_mode );
__EXPORT bool ChgLiteralInternal( XCTransactionVars* vars, bool pro_mode );
__EXPORT void DelLiteralInternal( XCTransactionVars* vars, bool pro_mode );

// litgroups.cpp
__EXPORT void LitGroupVerify( XCBuffer* buf, XCTransactionVars* vars, verify_type verify_mode, bool pro_mode );
__EXPORT bool LitGroupRetrieve( XCBuffer* buf, XCTransactionVars* vars );
__EXPORT void LitGroupChange( XCBuffer* input, XCBuffer* orig, XCTransactionVars* vars );
__EXPORT void LitGroupAdd( XCBuffer* buf, XCTransactionVars* vars, bool pro_mode );
__EXPORT void LitGroupDelete( XCBuffer* lit_group, XCTransactionVars* vars );

__EXPORT void AddLiteralGroupInternal( XCTransactionVars* vars, bool pro_mode );
__EXPORT bool ChgLiteralGroupInternal( XCTransactionVars* vars, bool pro_mode );
__EXPORT void DelLiteralGroupInternal( XCTransactionVars* vars, bool pro_mode );

// litrelate.cpp
__EXPORT void LitRelateVerify( XCBuffer* buf, XCTransactionVars* vars, verify_type verify_mode, bool pro_mode );
__EXPORT void LitRelateAdd( XCBuffer* buf, XCTransactionVars* vars );
__EXPORT void LitRelateDelete( XCBuffer* buf, XCTransactionVars* vars );

__EXPORT void AddLitToGroupInternal( XCTransactionVars* vars, bool pro_mode );
__EXPORT void DelLitFromGroupInternal( XCTransactionVars* vars, bool pro_mode );

// litvalues.cpp
__EXPORT bool LiteralValueRetrieve( XCBuffer* LiteralVal, XCTransactionVars* vars );
__EXPORT void LiteralValueAdd( XCBuffer* LiteralVal, XCTransactionVars* vars );
__EXPORT void LiteralValueChange( XCBuffer* LiteralVal, XCTransactionVars* vars, XCBuffer* orig=NULL );
__EXPORT void LiteralValueDelete( XCBuffer* LiteralVal, XCTransactionVars* vars );
__EXPORT void LiteralValueVerify( XCBuffer* input, XCTransactionVars* vars, verify_type verify_mode, XCBuffer* orig = NULL );


// messages.cpp
__EXPORT bool MessageDefnRetrieve( XCBuffer* input, XCTransactionVars* vars );
__EXPORT void MessageDefnVerify( XCBuffer* input, XCBuffer* master, verify_type verify_mode, XCTransactionVars* vars, bool pro_mode, XCBuffer* orig = NULL, bool* has_master = NULL );
__EXPORT void MessageDefnAdd( XCBuffer* buf, XCTransactionVars* vars );
__EXPORT void MessageDefnDelete( XCBuffer* buf, XCTransactionVars* vars );
__EXPORT void MessageDefnChange( XCBuffer* input, XCBuffer* compare, XCTransactionVars* vars );
__EXPORT void MessageDefnDeleteAll( XCBuffer* buf, XCTransactionVars* vars );

__EXPORT bool MessageMasterRetrieve( XCBuffer* input, XCTransactionVars* vars );
__EXPORT void MessageMasterAdd( XCBuffer* input, bool pro_mode, XCTransactionVars* vars );
__EXPORT void MessageMasterDel( XCBuffer* input, XCTransactionVars* vars );
__EXPORT void MessageMasterChange( XCBuffer* input, XCBuffer* original, XCTransactionVars* vars );

__EXPORT void DelMessageInternal( XCTransactionVars* vars, bool pro_mode );
__EXPORT void AddMessageInternal( XCTransactionVars* vars, bool pro_mode );

// relate.cpp
__EXPORT void DatasetDescrAdd( XCBuffer* buf, XCTransactionVars* vars );
__EXPORT void DatasetDescrChange( XCBuffer* buf, XCTransactionVars* vars );
__EXPORT void DatasetDescrDelete( XCBuffer* buf, XCTransactionVars* vars );
__EXPORT bool DatasetDescrRetrieve( XCBuffer* buf, XCTransactionVars* vars );
__EXPORT void DBRelateAdd( XCBuffer* buf, XCTransactionVars* vars );
__EXPORT void DBRelateDelete( XCBuffer* buf, XCTransactionVars* vars );
__EXPORT bool DBRelateRetrieve( XCBuffer* buf, XCTransactionVars* vars );
__EXPORT void DBRelateVerify( XCBuffer* buf, XCTransactionVars* vars, verify_type verify_mode );
__EXPORT XCDBStatement* DBRelateReviewFormat( XCBuffer* input, XCTransactionVars* vars );

// sysvals.cpp
__EXPORT void SystemValueVerify( XCBuffer* buf, verify_type verify_mode, XCTransactionVars* vars, XCBuffer* orig = NULL );
__EXPORT bool SystemValueRetrieve( XCBuffer* buf, XCTransactionVars* vars );
__EXPORT void SystemValueDeleteAll( XCBuffer* input, XCTransactionVars* vars );
__EXPORT void SystemValueChange( XCBuffer* input, XCBuffer* compare, XCTransactionVars* vars );

// transactions.cpp
__EXPORT bool TransactionRetrieve( XCBuffer* input, XCTransactionVars* vars );
__EXPORT void TransactionChange( XCBuffer* input, XCBuffer* original, XCTransactionVars* vars );
__EXPORT void TransactionVerify( XCBuffer* input, verify_type verify_mode, XCTransactionVars* vars );
__EXPORT void TransactionDeleteAll( XCBuffer* input, XCTransactionVars* vars );

// userexits.cpp
__EXPORT void UserExitDefnsVerify( XCBuffer* buf, verify_type verify_mode, XCTransactionVars* vars, XCBuffer* orig = NULL );
__EXPORT void UserExitDefnsChange( XCBuffer* input, XCBuffer* orig, XCTransactionVars* vars );
__EXPORT bool UserExitDefnsRetrieve( XCBuffer* buf, XCTransactionVars* vars );
__EXPORT void UserExitDefnDeleteAll( XCBuffer* buf, XCTransactionVars* vars );
__EXPORT XCDBStatement* UserExitList( XCBuffer* buf, XCTransactionVars* vars );

#endif
